package com.eco.fanliapp.service;

import com.eco.fanliapp.entity.AppGoods;
import com.eco.fanliapp.utils.DateFormatUtils;
import com.eco.fanliapp.vo.HaoDanKuItemInfo;
import com.eco.fanliapp.vo.TbkItemInfoGetInfo.NTbkItem;
import com.eco.fanliapp.vo.respone.DTKResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;


@Slf4j
public class HDKUtils {


    public static AppGoods getAppGoodsFromHDK(HaoDanKuItemInfo.DataBean itemData) {

        // 并将数据存储到商品表
        AppGoods appGoods = new AppGoods();
        //  appGoods.setCode(Long.parseLong(String.valueOf(infoHDK.getCode())));
        appGoods.setMe(itemData.getMe());
        appGoods.setProductId(itemData.getProduct_id());
        appGoods.setItemid(itemData.getItemid());
        appGoods.setSellerId(itemData.getSeller_id());
        appGoods.setSellerName(itemData.getSeller_name());
        appGoods.setItemtitle(itemData.getItemtitle());
        appGoods.setItemid(itemData.getItemid());
        appGoods.setItemshorttitle(itemData.getItemshorttitle());
        appGoods.setItemdesc(itemData.getItemdesc());
        appGoods.setItemprice(itemData.getItemprice());
        appGoods.setItemsale(Integer.parseInt(itemData.getItemsale() == null ? "0" : itemData.getItemsale()));
        appGoods.setItemsale2(Integer.parseInt(itemData.getItemsale2() == null ? "0" : itemData.getItemsale2()));
        appGoods.setItemTop(1);
        if (itemData.getItempic() != null && itemData.getItempic().contains(":////")) {
            String itemPic = itemData.getItempic().replace(":////", "://").trim();
            appGoods.setItempic(itemPic);
        } else {
            appGoods.setItempic(itemData.getItempic());
        }
        appGoods.setItemType(1); //商品类型
        appGoods.setTodaysale(Integer.parseInt(itemData.getTodaysale() == null ? "0" : itemData.getTodaysale()));
        appGoods.setItempicCopy(itemData.getItempic_copy());
        appGoods.setFqcat(itemData.getFqcat());
        appGoods.setShoptype(itemData.getShoptype());
        appGoods.setItemendprice(Double.parseDouble(itemData.getItemendprice() == null ? "0" : itemData.getItemendprice()));
        appGoods.setTkrates(itemData.getTkrates());
        appGoods.setTktype(itemData.getTktype());
        appGoods.setTkmoney(itemData.getTkmoney());
        appGoods.setCuntao(itemData.getCuntao());
        appGoods.setCouponurl(itemData.getCouponurl());
        appGoods.setCouponmoney(Double.parseDouble(itemData.getCouponmoney() == null ? "0" : itemData.getCouponmoney()));
        appGoods.setCouponsurplus(itemData.getCouponsurplus());
        appGoods.setCouponreceive(itemData.getCouponreceive());
        appGoods.setCouponreceive2(itemData.getCouponreceive2());
        appGoods.setCouponnum(itemData.getCouponnum());
        appGoods.setCouponCondition(itemData.getCoupon_condition());
        appGoods.setCouponexplain(itemData.getCouponexplain());
        appGoods.setTodaycouponreceive(itemData.getTodaycouponreceive());
        appGoods.setCouponstarttime(itemData.getCouponstarttime() == null ? "0" : itemData.getCouponstarttime() + "000");
        appGoods.setCouponendtime(itemData.getCouponendtime() == null ? "0" : itemData.getCouponendtime() + "000");
        appGoods.setStarttime(itemData.getStarttime() == null ? "0" : itemData.getStarttime() + "000");
        appGoods.setStartTime(itemData.getStart_time() == null ? "0" : itemData.getStart_time() + "000");
        appGoods.setEndTime(itemData.getEnd_time() == null ? "0" : itemData.getEnd_time() + "000");
        appGoods.setIsquality(itemData.getIsquality());
        appGoods.setIsBrand(itemData.getIs_brand());
        appGoods.setIsExplosion(itemData.getIs_explosion());
        appGoods.setIsLive(itemData.getIs_live());
        appGoods.setReportStatus(itemData.getReport_status());
//        appGoods.setVideoid(itemData.getVideoid());
        appGoods.setActivityid(itemData.getActivityid());
        appGoods.setActivityType(itemData.getActivity_type());

        appGoods.setGuideArticle(itemData.getGuide_article());
        appGoods.setGeneralIndex(itemData.getGeneral_index());
        appGoods.setPlanlink(itemData.getPlanlink());
        appGoods.setSellernick(itemData.getSellernick());
        appGoods.setUserid(itemData.getUserid());
        appGoods.setShopname(itemData.getShopname());
        appGoods.setShopid(itemData.getShopid());
        appGoods.setShoptype(itemData.getShoptype());
        appGoods.setOnlineUsers(itemData.getOnline_users());
        appGoods.setOriginalArticle(itemData.getOriginal_article());
        appGoods.setOriginalImg(itemData.getOriginal_img());
        appGoods.setOriginalArticle(itemData.getOriginal_article());
        appGoods.setDiscount(itemData.getDiscount());
        if (itemData.getTaobao_image() != null && itemData.getTaobao_image().contains(":////")) {
            String taobao_image = itemData.getTaobao_image().replace(":////", "://").trim();
            appGoods.setTaobaoImage(taobao_image);
        } else {
            appGoods.setTaobaoImage(itemData.getTaobao_image());
        }
        appGoods.setSonCategory(itemData.getSon_category());
        appGoods.setVideoid(itemData.getVideoid());

        if (itemData == null || itemData.getFqcat() == null) {

            return appGoods;
        }

        //1女装，2男装，3内衣，4美妆，5配饰，6鞋品，7箱包，8儿童，9母婴，10居家，11美食，12数码，13家电，14其他，15车品，16文体
//        switch (itemData.getFqcat()) {
//            case "5":
//                appGoods.setFqcat("3");
//                break;
//            case "7":
//                appGoods.setFqcat("6");
//                break;
//            case "8":
//                appGoods.setFqcat("9");
//                break;
//            case "13":
//                appGoods.setFqcat("12");
//                break;
//            case "16":
//                appGoods.setFqcat("15");
//                break;
//            default:
//                appGoods.setFqcat("0");
//                break;
//        }
        return appGoods;

    }

    public static AppGoods getAppGoodsFromTB(NTbkItem result) {

        AppGoods appGoods = new AppGoods();
        appGoods.setItemType(1);
        appGoods.setItemTop(1);
        appGoods.setItemid(result.getNumIid().toString());
        appGoods.setItempic(result.getPictUrl());
        //appGoods.setItemprice(result.getZkFinalPrice());
        appGoods.setItemtitle(result.getTitle());
        appGoods.setItemshorttitle(result.getTitle());
        appGoods.setShoptype(result.getUserType() == 1 ? "B" : "C");
        appGoods.setSellerId(result.getSellerId().toString());
        appGoods.setShopname(result.getNick());
        if (result.getSmallImages() == null || //获取商品图片列表
                result.getSmallImages().size() < 0) {
            appGoods.setTaobaoImage("");
        } else {
            appGoods.setTaobaoImage(result.getSmallImages().toString().replace("[", "").
                    replace("]", "").replace(" ", ""));
        }
        appGoods.setItemsale(result.getVolume().intValue());
//		appGoods.setFqcat(String.valueOf((result.getFqcat())));
        // 商品类目1女装，2男装，3内衣，4美妆，5配饰，6鞋品，7箱包，
        // 8儿童，9母婴，10居家，11美食，12数码，13家电，14其他，15车品，
        // 16文体，17宠物
        switch (result.getCatName()) {
            case "女装":
                appGoods.setFqcat("1");
                break;
            case "男装":
                appGoods.setFqcat("2");
                break;
            case "内衣":
                appGoods.setFqcat("3");
                break;
            case "美妆":
                appGoods.setFqcat("4");
                break;
            case "鞋品":
                appGoods.setFqcat("6");
                break;
            case "箱包":
                appGoods.setFqcat("6");
                break;
            case "母婴":
                appGoods.setFqcat("9");
                break;
            case "居家":
                appGoods.setFqcat("10");
                break;
            case "美食":
                appGoods.setFqcat("11");
                break;
            case "数码":
                appGoods.setFqcat("12");
                break;
            case "配饰":
                appGoods.setFqcat("3");
                break;
            case "儿童":
                appGoods.setFqcat("9");
                break;
            case "家电":
                appGoods.setFqcat("12");
                break;
            case "车品":
                appGoods.setFqcat("15");
                break;
            case "文体":
                appGoods.setFqcat("15");
                break;
            default:
                appGoods.setFqcat("0");
                break;
        }
        return appGoods;
    }

    public static AppGoods getAppGoodsFromHDKYangMao(HaoDanKuItemInfo.DataBean itemData, AppGoods appGoods) {

        // 并将数据存储到商品表
//        AppGoods appGoods = new AppGoods();
        //  appGoods.setCode(Long.parseLong(String.valueOf(infoHDK.getCode())));
        appGoods.setMe(itemData.getMe());
        appGoods.setProductId(itemData.getProduct_id());
        appGoods.setItemid(itemData.getItemid());
        appGoods.setSellerId(itemData.getSeller_id());
        appGoods.setSellerName(itemData.getSeller_name());
//        appGoods.setItemtitle(itemData.getItemtitle());
        appGoods.setItemid(itemData.getItemid());
        appGoods.setItemshorttitle(itemData.getItemshorttitle());
        appGoods.setItemdesc(itemData.getItemdesc());
//        appGoods.setItemprice(itemData.getItemprice());
        appGoods.setItemsale(Integer.parseInt(itemData.getItemsale() == null ? "0" : itemData.getItemsale()));
        appGoods.setItemsale2(Integer.parseInt(itemData.getItemsale2() == null ? "0" : itemData.getItemsale2()));
        appGoods.setItemTop(1);
//        appGoods.setItempic(itemData.getItempic());
        appGoods.setItemType(1); //商品类型
        appGoods.setTodaysale(Integer.parseInt(itemData.getTodaysale() == null ? "0" : itemData.getTodaysale()));
        appGoods.setItempicCopy(itemData.getItempic_copy());
        appGoods.setFqcat(itemData.getFqcat());
        appGoods.setShoptype(itemData.getShoptype());
//        appGoods.setItemendprice(Double.parseDouble(itemData.getItemendprice() == null ? "0" : itemData.getItemendprice()));
        appGoods.setTkrates(itemData.getTkrates());
        appGoods.setTktype(itemData.getTktype());
        appGoods.setTkmoney(itemData.getTkmoney());
        appGoods.setCuntao(itemData.getCuntao());
        appGoods.setCouponurl(itemData.getCouponurl());
//        appGoods.setCouponmoney(Double.parseDouble(itemData.getCouponmoney() == null ? "0" : itemData.getCouponmoney()));
        appGoods.setCouponsurplus(itemData.getCouponsurplus());
        appGoods.setCouponreceive(itemData.getCouponreceive());
        appGoods.setCouponreceive2(itemData.getCouponreceive2());
        appGoods.setCouponnum(itemData.getCouponnum());
        appGoods.setCouponCondition(itemData.getCoupon_condition());
        appGoods.setCouponexplain(itemData.getCouponexplain());
        appGoods.setTodaycouponreceive(itemData.getTodaycouponreceive());
        appGoods.setCouponstarttime(itemData.getCouponstarttime() == null ? "0" : itemData.getCouponstarttime() + "000");
        appGoods.setCouponendtime(itemData.getCouponendtime() == null ? "0" : itemData.getCouponendtime() + "000");
        appGoods.setStarttime(itemData.getStarttime() == null ? "0" : itemData.getStarttime() + "000");
        appGoods.setStartTime(itemData.getStart_time() == null ? "0" : itemData.getStart_time() + "000");
        appGoods.setEndTime(itemData.getEnd_time() == null ? "0" : itemData.getEnd_time() + "000");
        appGoods.setIsquality(itemData.getIsquality());
        appGoods.setIsBrand(itemData.getIs_brand());
        appGoods.setIsExplosion(itemData.getIs_explosion());
        appGoods.setIsLive(itemData.getIs_live());
        appGoods.setReportStatus(itemData.getReport_status());
//        appGoods.setVideoid(itemData.getVideoid());
        appGoods.setActivityid(itemData.getActivityid());
        appGoods.setActivityType(itemData.getActivity_type());

        appGoods.setGuideArticle(itemData.getGuide_article());
        appGoods.setGeneralIndex(itemData.getGeneral_index());
        appGoods.setPlanlink(itemData.getPlanlink());
        appGoods.setSellernick(itemData.getSellernick());
        appGoods.setUserid(itemData.getUserid());
        appGoods.setShopname(itemData.getShopname());
        appGoods.setShopid(itemData.getShopid());
        appGoods.setShoptype(itemData.getShoptype());
        appGoods.setOnlineUsers(itemData.getOnline_users());
        appGoods.setOriginalArticle(itemData.getOriginal_article());
        appGoods.setOriginalImg(itemData.getOriginal_img());
        appGoods.setOriginalArticle(itemData.getOriginal_article());
        appGoods.setDiscount(itemData.getDiscount());
        appGoods.setTaobaoImage(itemData.getTaobao_image());
        appGoods.setSonCategory(itemData.getSon_category());
        appGoods.setVideoid(itemData.getVideoid());
        if (itemData == null || itemData.getFqcat() == null) {

            return appGoods;
        }

        //1女装，2男装，3内衣，4美妆，5配饰，6鞋品，7箱包，8儿童，9母婴，10居家，11美食，12数码，13家电，14其他，15车品，16文体
        switch (itemData.getFqcat()) {
            case "5":
                appGoods.setFqcat("3");
                break;
            case "7":
                appGoods.setFqcat("6");
                break;
            case "8":
                appGoods.setFqcat("9");
                break;
            case "13":
                appGoods.setFqcat("12");
                break;
            case "16":
                appGoods.setFqcat("15");
                break;
            default:
                appGoods.setFqcat("0");
                break;
        }

        return appGoods;

    }

    public static AppGoods getAppGoodsFromDTKYangMao(DTKResponse.DataBean itemData, AppGoods appGoods) {

        // 并将数据存储到商品表
//		AppGoods appGoods = new AppGoods();
        //  appGoods.setCode(Long.parseLong(String.valueOf(infoHDK.getCode())));
//        appGoods.setMe(itemData.getMe());
        appGoods.setProductId(itemData.getId());
        appGoods.setItemid(itemData.getGoodsId());
        appGoods.setSellerId(itemData.getSellerId());
        appGoods.setSellerName(itemData.getShopName());
//        appGoods.setItemtitle(itemData.getTitle());
        appGoods.setItemid(itemData.getGoodsId());
        appGoods.setItemshorttitle(itemData.getDtitle());
        appGoods.setItemdesc(itemData.getDesc());

//        appGoods.setItemprice(itemData.getOriginalPrice());
        appGoods.setItemsale(Integer.parseInt(itemData.getMonthSales() == null ? "0" : itemData.getMonthSales()));
        appGoods.setItemsale2(Integer.parseInt(itemData.getTwoHoursSales() == null ? "0" : itemData.getTwoHoursSales()));
        appGoods.setItemTop(1);
        String mainPic = itemData.getMainPic();
//        appGoods.setItempic(mainPic.startsWith("https") ? mainPic : "https:" + mainPic);
        appGoods.setItemType(1); //商品类型
        appGoods.setTodaysale(Integer.parseInt(itemData.getDailySales() == null ? "0" : itemData.getDailySales()));
        appGoods.setItempicCopy(itemData.getMarketingMainPic());
//        appGoods.setFqcat(itemData.getCid());
        appGoods.setShoptype(itemData.getShopType());
//		appGoods.setItemendprice(Double.parseDouble(itemData.getActualPrice() == null ? "0" : itemData.getActualPrice()));
        appGoods.setTkrates(itemData.getCommissionRate());
        appGoods.setTktype(itemData.getCommissionType());
//        appGoods.setTkmoney(itemData.getTkmoney());
        appGoods.setCuntao(itemData.getHaitao());
        appGoods.setCouponurl(itemData.getCouponLink());
//		appGoods.setCouponmoney(Double.parseDouble(itemData.getCouponPrice() == null ? "0" : itemData.getCouponPrice()));
        try {
            if (!StringUtils.isEmpty(itemData.getCouponTotalNum()) && !StringUtils.isEmpty(itemData.getCouponReceiveNum())) {
                appGoods.setCouponsurplus(String.valueOf(Integer.valueOf(itemData.getCouponTotalNum()) - Integer.valueOf(itemData.getCouponReceiveNum())));
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("优惠券数量转换异常");
        }
        appGoods.setCouponnum(itemData.getCouponTotalNum());
//        appGoods.setCouponreceive(itemData.getCouponreceive());
//        appGoods.setCouponreceive2(itemData.getCouponreceive2());
//        appGoods.setCouponCondition(itemData.getCoupon_condition());
//        appGoods.setCouponexplain(itemData.getCouponexplain());
//        appGoods.setTodaycouponreceive(itemData.getTodaycouponreceive());

        try {

            if (!StringUtils.isEmpty(itemData.getCouponStartTime())) {
                long couponStartTime = 0L;
                if (itemData.getCouponStartTime().length() > 11) {
                    couponStartTime = DateFormatUtils.stringToLong(itemData.getCouponStartTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    couponStartTime = DateFormatUtils.stringToLong(itemData.getCouponStartTime(), DateFormatUtils.STANDARD_FORMAT1);
                }

                appGoods.setCouponstarttime(String.valueOf(couponStartTime));
            }
            if (!StringUtils.isEmpty(itemData.getCouponEndTime())) {
                long couponEndTime = 0L;
                if (itemData.getCouponEndTime().length() > 11) {
                    couponEndTime = DateFormatUtils.stringToLong(itemData.getCouponEndTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    couponEndTime = DateFormatUtils.stringToLong(itemData.getCouponEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                }
//                long couponEndTime = DateFormatUtils.stringToLong(itemData.getCouponEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                appGoods.setCouponendtime(String.valueOf(couponEndTime));
            }
            if (!StringUtils.isEmpty(itemData.getActivityStartTime())) {
                long activityStartTime = 0L;
                if (itemData.getActivityStartTime().length() > 11) {
                    activityStartTime = DateFormatUtils.stringToLong(itemData.getActivityStartTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    activityStartTime = DateFormatUtils.stringToLong(itemData.getActivityStartTime(), DateFormatUtils.STANDARD_FORMAT1);
                }
//                long activityStartTime = DateFormatUtils.stringToLong(itemData.getActivityStartTime(), DateFormatUtils.STANDARD_FORMAT1);
                appGoods.setStartTime(String.valueOf(activityStartTime));
            }
            if (!StringUtils.isEmpty(itemData.getActivityEndTime())) {
                long activityEndTime = 0L;
                if (itemData.getActivityEndTime().length() > 11) {
                    activityEndTime = DateFormatUtils.stringToLong(itemData.getActivityEndTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    activityEndTime = DateFormatUtils.stringToLong(itemData.getActivityEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                }
//                long activityEndTime = DateFormatUtils.stringToLong(itemData.getActivityEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                appGoods.setEndTime(String.valueOf(activityEndTime));
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("日期转换异常");
        }
        appGoods.setIsBrand(itemData.getBrand());
        if (("1").equals(itemData.getActivityType())) {
            appGoods.setActivityType("普通活动");
        }
        if (("2").equals(itemData.getActivityType())) {
            appGoods.setActivityType("淘抢购");
        }
        if (("3").equals(itemData.getActivityType())) {
            appGoods.setActivityType("聚划算");
        }
        appGoods.setGuideArticle(itemData.getDesc());
        appGoods.setShopname(itemData.getShopName());
        appGoods.setShopid(itemData.getSellerId());

        if ("1".equals(itemData.getShopType())) {
            appGoods.setShoptype("B");
        }
        if ("0".equals(itemData.getShopType())) {
            appGoods.setShoptype("C");
        }
        BigDecimal commissionRate = new BigDecimal(itemData.getCommissionRate() == null ? "0" : itemData.getCommissionRate());
//		BigDecimal originalPrice = new BigDecimal(itemData.getOriginalPrice() == null ? "0" : itemData.getOriginalPrice());
//		BigDecimal couponPrice = new BigDecimal(itemData.getCouponPrice() == null ? "0" : itemData.getCouponPrice());
//		BigDecimal actualPrice = new BigDecimal(itemData.getActualPrice() == null ? "0" : itemData.getActualPrice());
//		BigDecimal couponAfterPrice = null;
//		if (!"0".equals(itemData.getCouponPrice())) {
//			couponAfterPrice = originalPrice.subtract(couponPrice);
//		} else {
//			couponAfterPrice = originalPrice.subtract(couponPrice);
//            if (actualPrice.compareTo(couponAfterPrice) < 0) {
//                couponAfterPrice = actualPrice;
//            }
//		}
//		appGoods.setItemendprice(couponAfterPrice.doubleValue());
        String tkmoney = commissionRate.multiply(new BigDecimal(appGoods.getItemendprice())).multiply(new BigDecimal(0.01)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
        appGoods.setTkmoney(tkmoney);
        //1 -女装，2 -母婴，3 -美妆，4 -居家日用，5 -鞋品，6 -美食，7 -文娱车品，8 -数码家电，9 -男装，10 -内衣，11 -箱包，12 -配饰，13 -户外运动，14 -家装家纺
        if (itemData == null || itemData.getCid() == null) {
            return appGoods;
        }
        switch (itemData.getCid()) {
            case "1":
                appGoods.setFqcat("1");
                break;
            case "2":
                appGoods.setFqcat("9");
                break;
            case "3":
                appGoods.setFqcat("4");
                break;
            case "4":
                appGoods.setFqcat("10");
                break;
            case "5":
                appGoods.setFqcat("6");
                break;
            case "6":
                appGoods.setFqcat("11");
                break;
            case "7":
                appGoods.setFqcat("15");
                break;
            case "8":
                appGoods.setFqcat("12");
                break;
            case "9":
                appGoods.setFqcat("2");
                break;
            case "10":
                appGoods.setFqcat("3");
                break;
            case "11":
                appGoods.setFqcat("6");
                break;
            case "12":
                appGoods.setFqcat("3");
                break;
            case "13":
                appGoods.setFqcat("15");
                break;
            case "14":
                appGoods.setFqcat("10");
                break;

            default:
                appGoods.setFqcat("0");
                break;
        }
        return appGoods;
    }

    public static AppGoods getAppGoodsFromDTK(DTKResponse.DataBean itemData) {

        // 并将数据存储到商品表
        AppGoods appGoods = new AppGoods();
        //  appGoods.setCode(Long.parseLong(String.valueOf(infoHDK.getCode())));
//        appGoods.setMe(itemData.getMe());
        appGoods.setProductId(itemData.getId());
        appGoods.setItemid(itemData.getGoodsId());
        appGoods.setSellerId(itemData.getSellerId());
        appGoods.setSellerName(itemData.getShopName());
        appGoods.setItemtitle(itemData.getTitle());
        appGoods.setItemid(itemData.getGoodsId());
        appGoods.setItemshorttitle(itemData.getDtitle());
        appGoods.setItemdesc(itemData.getDesc());
        appGoods.setItemprice(itemData.getOriginalPrice());
        appGoods.setItemsale(Integer.parseInt(itemData.getMonthSales() == null ? "0" : itemData.getMonthSales()));
        appGoods.setItemsale2(Integer.parseInt(itemData.getTwoHoursSales() == null ? "0" : itemData.getTwoHoursSales()));
        appGoods.setItemTop(1);
        String mainPic = itemData.getMainPic();
        appGoods.setItempic(mainPic.startsWith("https") ? mainPic : "https:" + mainPic);
        appGoods.setItemType(1); //商品类型
        appGoods.setTodaysale(Integer.parseInt(itemData.getDailySales() == null ? "0" : itemData.getDailySales()));
        appGoods.setItempicCopy(itemData.getMarketingMainPic());
//        appGoods.setFqcat(itemData.getCid());
        appGoods.setShoptype(itemData.getShopType());
        appGoods.setItemendprice(Double.parseDouble(itemData.getOriginalPrice() == null ? "0" : itemData.getOriginalPrice()));
        appGoods.setTkrates(itemData.getCommissionRate());
        appGoods.setTktype(itemData.getCommissionType());
//        appGoods.setTkmoney(itemData.getTkmoney());
        appGoods.setCuntao(itemData.getHaitao());
        appGoods.setCouponurl(itemData.getCouponLink());
        appGoods.setCouponmoney(Double.parseDouble(itemData.getCouponPrice() == null ? "0" : itemData.getCouponPrice()));
        try {
            if (!StringUtils.isEmpty(itemData.getCouponTotalNum()) && !StringUtils.isEmpty(itemData.getCouponReceiveNum())) {
                appGoods.setCouponsurplus(String.valueOf(Integer.valueOf(itemData.getCouponTotalNum()) - Integer.valueOf(itemData.getCouponReceiveNum())));
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("优惠券数量转换异常");
        }
        appGoods.setCouponnum(itemData.getCouponTotalNum());
//        appGoods.setCouponreceive(itemData.getCouponreceive());
//        appGoods.setCouponreceive2(itemData.getCouponreceive2());
//        appGoods.setCouponCondition(itemData.getCoupon_condition());
//        appGoods.setCouponexplain(itemData.getCouponexplain());
//        appGoods.setTodaycouponreceive(itemData.getTodaycouponreceive());

        try {

            if (!StringUtils.isEmpty(itemData.getCouponStartTime())) {
                long couponStartTime = 0L;
                if (itemData.getCouponStartTime().length() > 11) {
                    couponStartTime = DateFormatUtils.stringToLong(itemData.getCouponStartTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    couponStartTime = DateFormatUtils.stringToLong(itemData.getCouponStartTime(), DateFormatUtils.STANDARD_FORMAT1);
                }

                appGoods.setCouponstarttime(String.valueOf(couponStartTime));
            }
            if (!StringUtils.isEmpty(itemData.getCouponEndTime())) {
                long couponEndTime = 0L;
                if (itemData.getCouponEndTime().length() > 11) {
                    couponEndTime = DateFormatUtils.stringToLong(itemData.getCouponEndTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    couponEndTime = DateFormatUtils.stringToLong(itemData.getCouponEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                }
//                long couponEndTime = DateFormatUtils.stringToLong(itemData.getCouponEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                appGoods.setCouponendtime(String.valueOf(couponEndTime));
            }
            if (!StringUtils.isEmpty(itemData.getActivityStartTime())) {
                long activityStartTime = 0L;
                if (itemData.getActivityStartTime().length() > 11) {
                    activityStartTime = DateFormatUtils.stringToLong(itemData.getActivityStartTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    activityStartTime = DateFormatUtils.stringToLong(itemData.getActivityStartTime(), DateFormatUtils.STANDARD_FORMAT1);
                }
//                long activityStartTime = DateFormatUtils.stringToLong(itemData.getActivityStartTime(), DateFormatUtils.STANDARD_FORMAT1);
                appGoods.setStartTime(String.valueOf(activityStartTime));
            }
            if (!StringUtils.isEmpty(itemData.getActivityEndTime())) {
                long activityEndTime = 0L;
                if (itemData.getActivityEndTime().length() > 11) {
                    activityEndTime = DateFormatUtils.stringToLong(itemData.getActivityEndTime(), DateFormatUtils.STANDARD_FORMAT);
                } else {
                    activityEndTime = DateFormatUtils.stringToLong(itemData.getActivityEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                }
//                long activityEndTime = DateFormatUtils.stringToLong(itemData.getActivityEndTime(), DateFormatUtils.STANDARD_FORMAT1);
                appGoods.setEndTime(String.valueOf(activityEndTime));
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("日期转换异常");
        }
//        appGoods.setIsquality(itemData.getIsquality());
        appGoods.setIsBrand(itemData.getBrand());
//        appGoods.setIsExplosion(itemData.getIs_explosion());
//        appGoods.setIsLive(itemData.getIs_live());
//        appGoods.setReportStatus(itemData.getReport_status());
//        appGoods.setVideoid(itemData.getVideoid());
//        appGoods.setActivityid(itemData.getActivityid());
        if (("1").equals(itemData.getActivityType())) {
            appGoods.setActivityType("普通活动");
        }
        if (("2").equals(itemData.getActivityType())) {
            appGoods.setActivityType("淘抢购");
        }
        if (("3").equals(itemData.getActivityType())) {
            appGoods.setActivityType("聚划算");
        }
        // appGoods.setActivityType(itemData.getActivityType());
        appGoods.setGuideArticle(itemData.getDesc());
//        appGoods.setGeneralIndex(itemData.getGeneral_index());
//        appGoods.setPlanlink(itemData.getPlanlink());
//        appGoods.setSellernick(itemData.getShopName());
//        appGoods.setUserid(itemData.getUserid());
        appGoods.setShopname(itemData.getShopName());
        appGoods.setShopid(itemData.getSellerId());

        if ("1".equals(itemData.getShopType())) {
            appGoods.setShoptype("B");
        }
        if ("0".equals(itemData.getShopType())) {
            appGoods.setShoptype("C");
        }
//        appGoods.setOnlineUsers(itemData.getOnline_users());
//        appGoods.setOriginalArticle(itemData.getOriginal_article());
//        appGoods.setOriginalImg(itemData.getOriginal_img());
//        appGoods.setOriginalArticle(itemData.getOriginal_article());
//        appGoods.setDiscount(itemData.getDiscount());
//        appGoods.setTaobaoImage(itemData.getTaobao_image());
//        appGoods.setSonCategory(itemData.getSon_category());
        BigDecimal commissionRate = new BigDecimal(itemData.getCommissionRate() == null ? "0" : itemData.getCommissionRate());
        BigDecimal originalPrice = new BigDecimal(itemData.getOriginalPrice() == null ? "0" : itemData.getOriginalPrice());
        BigDecimal couponPrice = new BigDecimal(itemData.getCouponPrice() == null ? "0" : itemData.getCouponPrice());
        BigDecimal actualPrice = new BigDecimal(itemData.getActualPrice() == null ? "0" : itemData.getActualPrice());
        BigDecimal couponAfterPrice = null;
        if (!"0".equals(itemData.getCouponPrice())) {
            couponAfterPrice = originalPrice.subtract(couponPrice);
        } else {
            couponAfterPrice = originalPrice.subtract(couponPrice);
//            if (actualPrice.compareTo(couponAfterPrice) < 0) {
//                couponAfterPrice = actualPrice;
//            }
        }
        appGoods.setItemendprice(couponAfterPrice.doubleValue());
        String tkmoney = commissionRate.multiply(couponAfterPrice).multiply(new BigDecimal(0.01)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
        appGoods.setTkmoney(tkmoney);
        //1 -女装，2 -母婴，3 -美妆，4 -居家日用，5 -鞋品，6 -美食，7 -文娱车品，8 -数码家电，9 -男装，10 -内衣，11 -箱包，12 -配饰，13 -户外运动，14 -家装家纺
        if (itemData == null || itemData.getCid() == null) {
            return appGoods;
        }
        switch (itemData.getCid()) {
            case "1":
                appGoods.setFqcat("1");
                break;
            case "2":
                appGoods.setFqcat("9");
                break;
            case "3":
                appGoods.setFqcat("4");
                break;
            case "4":
                appGoods.setFqcat("10");
                break;
            case "5":
                appGoods.setFqcat("6");
                break;
            case "6":
                appGoods.setFqcat("11");
                break;
            case "7":
                appGoods.setFqcat("15");
                break;
            case "8":
                appGoods.setFqcat("12");
                break;
            case "9":
                appGoods.setFqcat("2");
                break;
            case "10":
                appGoods.setFqcat("3");
                break;
            case "11":
                appGoods.setFqcat("6");
                break;
            case "12":
                appGoods.setFqcat("3");
                break;
            case "13":
                appGoods.setFqcat("15");
                break;
            case "14":
                appGoods.setFqcat("10");
                break;

            default:
                appGoods.setFqcat("0");
                break;
        }
        return appGoods;
    }

    public static AppGoods getUpdateAppGoodsFromDTK(DTKResponse.DataBean itemData, AppGoods appGoods) {

        //  AppGoods appGoods = new AppGoods();
        appGoods.setProductId(itemData.getId());
        appGoods.setItemid(itemData.getGoodsId());
        appGoods.setItemprice(itemData.getOriginalPrice());
        appGoods.setItemsale(Integer.parseInt(itemData.getMonthSales() == null ? "0" : itemData.getMonthSales()));
        appGoods.setItemsale2(Integer.parseInt(itemData.getTwoHoursSales() == null ? "0" : itemData.getTwoHoursSales()));
        appGoods.setItemendprice(Double.parseDouble(itemData.getActualPrice() == null ? "0" : itemData.getActualPrice()));
        appGoods.setTkrates(itemData.getCommissionRate());
        appGoods.setTktype(itemData.getCommissionType());
        appGoods.setDiscount(itemData.getDiscounts());
        BigDecimal commissionRate = new BigDecimal(itemData.getCommissionRate() == null ? "0" : itemData.getCommissionRate());
        BigDecimal originalPrice = new BigDecimal(itemData.getOriginalPrice() == null ? "0" : itemData.getOriginalPrice());
        BigDecimal couponPrice = new BigDecimal(itemData.getCouponPrice() == null ? "0" : itemData.getCouponPrice());
        BigDecimal actualPrice = new BigDecimal(itemData.getActualPrice() == null ? "0" : itemData.getActualPrice());

        BigDecimal couponAfterPrice = originalPrice.subtract(couponPrice);
        if (actualPrice.compareTo(couponAfterPrice) < 0) {
            couponAfterPrice = actualPrice;
        }
        String tkmoney = commissionRate.multiply(couponAfterPrice).multiply(new BigDecimal(0.01)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
        appGoods.setTkmoney(tkmoney);
        appGoods.setRecommend(0);
        appGoods.setCouponmoney(couponPrice.doubleValue());
        return appGoods;
    }
}

